# Generated by Django 4.2.1 on 2023-09-05 18:26

from django.db import migrations


class Migration(migrations.Migration):
    """
    Rename existing processor slugs to match the new naming convention
    """

    def rename_slugs(apps, schema_editor):
        ApiBackend = apps.get_model('apiabstractor', 'ApiBackend')
        slug_map = {
            'openai_completions': 'completions',
            'openai_image_generations': 'image_generations',
            'stabilityai_text2image': 'text2image',
            'cohere_generate': 'generate',
            'openai_chatgpt': 'chatgpt',
            'promptly_text_chat': 'text_chat',
            'openai_audio_transcriptions': 'audio_transcriptions',
            'openai_audio_translations': 'audio_translations',
            'promptly_http_uri_text_extract': 'http_uri_text_extract',
            'promptly_data_uri_text_extract': 'data_uri_text_extract',
            'promptly_data_source_search': 'datasource_search',
            'azure_chatgpt': 'chatgpt',
            'elevenlabs_text_to_speech': 'text_to_speech',
            'openai_images_variations': 'images_variations',
            'openai_images_edit': 'images_edit',
            'google_text_chat': 'text_chat',
            'google_text': 'text',
            'promptly_text_summarizer': 'text_summarizer',
            'localai_completions': 'completions',
            'localai_chatcompletions': 'chatgpt',
        }

        for old_slug, new_slug in slug_map.items():
            ApiBackend.objects.filter(slug=old_slug).update(slug=new_slug)

    dependencies = [
        ('apiabstractor', '0002_initial'),
    ]

    operations = [
        migrations.RunPython(
            rename_slugs, reverse_code=migrations.RunPython.noop),
    ]
